package com.though.alipay.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;


public class AlipayConfig {

	public static final String FORMAT = "json";
	
	public static final String ENCODING = "UTF-8";
	
	public static final String RSA2 = "RSA2";
	
	private static final AlipayParams params = new AlipayParams();	
	
	private static final String CONFIG = "/alipay-config.properties";

	private static final String CONFIG_TEMPLATE = "/alipay-config-template.properties";
	
	private static final String FRAME_CONFIG = "/framework-alipay-config.properties";

	static {
		 try {
			InputStream in = AlipayConfig.class.getResourceAsStream(FRAME_CONFIG);
			if (in == null) {
				in = AlipayConfig.class.getResourceAsStream(CONFIG);
				if (in == null) {
					in = AlipayConfig.class.getResourceAsStream(CONFIG_TEMPLATE);
					if (in == null) throw new RuntimeException("alipay-config.properties is not config");
				}
			}

			Properties prop = new Properties();
			prop.load(in);

			params.setAlipublicKey(prop.getProperty("alipay_alipublicKey"));
			params.setAppid(prop.getProperty("alipay_appid"));
			params.setGatway(prop.getProperty("alipay_gatway"));
			params.setPartner(prop.getProperty("alipay_partner"));
			params.setPrivateKey(prop.getProperty("alipay_privateKey"));
			params.setPublicKey(prop.getProperty("alipay_publicKey"));
			params.setSeller(prop.getProperty("alipay_seller"));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static AlipayParams getParams() {
		return params;
	}
}